// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.audio.parameters;

import zombie.audio.FMODGlobalParameter;
import zombie.characters.IsoPlayer;

public final class ParameterMusicWakeState extends FMODGlobalParameter {
    private int m_playerIndex = -1;
    private ParameterMusicWakeState.State m_state = ParameterMusicWakeState.State.Awake;

    public ParameterMusicWakeState() {
        super("MusicWakeState");
    }

    @Override
    public float calculateCurrentValue() {
        IsoPlayer isoPlayer = this.choosePlayer();
        if (isoPlayer != null && this.m_state == ParameterMusicWakeState.State.Awake && isoPlayer.isAsleep()) {
            this.m_state = ParameterMusicWakeState.State.Sleeping;
        }

        return (float)this.m_state.label;
    }

    public void setState(IsoPlayer player, ParameterMusicWakeState.State state) {
        if (player == this.choosePlayer()) {
            this.m_state = state;
        }
    }

    private IsoPlayer choosePlayer() {
        if (this.m_playerIndex != -1) {
            IsoPlayer isoPlayer0 = IsoPlayer.players[this.m_playerIndex];
            if (isoPlayer0 == null || isoPlayer0.isDead()) {
                this.m_playerIndex = -1;
            }
        }

        if (this.m_playerIndex != -1) {
            return IsoPlayer.players[this.m_playerIndex];
        } else {
            for (int _int = 0; _int < IsoPlayer.numPlayers; _int++) {
                IsoPlayer isoPlayer1 = IsoPlayer.players[_int];
                if (isoPlayer1 != null && !isoPlayer1.isDead()) {
                    this.m_playerIndex = _int;
                    this.m_state = isoPlayer1.isAsleep() ? ParameterMusicWakeState.State.Sleeping : ParameterMusicWakeState.State.Awake;
                    return isoPlayer1;
                }
            }

            return null;
        }
    }

    public static enum State {
        Awake(0),
        Sleeping(1),
        WakeNormal(2),
        WakeNightmare(3),
        WakeZombies(4);

        final int label;

        private State(int int1) {
            this.label = int1;
        }
    }
}
